﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Common.Enums.Archives;
using S.EarTag.Read.API.Application.MediatorCommand.BodyMeasureCommand;

namespace S.EarTag.Read.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BodyMeasureController : ControllerBase
    {
        private readonly IMediator _mediator;
        public BodyMeasureController(IMediator mediator)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 根据可视耳号反填体尺测定信息
        /// </summary>
        /// <param name="EarTag"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetBodyEarTag(string? EarTag)
        {
            BodyMeasureEarTagCommand command = new BodyMeasureEarTagCommand();
            command.EarTag = EarTag;
            var response =await _mediator.Send(command);
            return Ok(response);
        }
        /// <summary>
        /// 根据Id查询体尺数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetByIdBodyMeasure(int id)
        {
            BodyMeasureByIdCommand command = new BodyMeasureByIdCommand();
            command.BodyMeasureId = id;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 查询分页显示
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="EarTag"></param>
        /// <param name="VarietyEnum"></param>
        /// <param name="Sex"></param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public async Task<IActionResult> GetBodyMeasureListPage(int pageIndex=1, int pageSize=12,string? EarTag="", int VarietyEnum=0,int Sex=0)
        {
            BodyMeasureListPageCommand command = new BodyMeasureListPageCommand();
            command.pageIndex= pageIndex;
            command.pageSize= pageSize;
            command.EarTag= EarTag;
            command.VarietyEnum = VarietyEnum;
            command.Sex= Sex;
            var list=await _mediator.Send(command);
            return Ok(list);
        }
    }
}
